/*
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#include <mctp/mctp.h>

#include <functional>

namespace dev {

namespace {
using request_handler_t =
    std::function<bool(const mc::dict&, const std::vector<uint8_t>&, std::string&)>;

request_handler_t& get_request_handler() {
    static request_handler_t handler;
    return handler;
}
} // namespace

void set_mctp_request_handler(request_handler_t handler) {
    get_request_handler() = std::move(handler);
}

mctp::mctp(mc::engine::abstract_object* /*parent*/, uint16_t /*phy_addr*/, MCTP_MESSAGE_TYPE /*msg_type*/,
           std::string /*position*/)
    : mc::core::object(nullptr) {
}

mctp::~mctp() = default;

void mctp::create_transport_obj(mc::dict& /*object*/) {
}

void mctp::try_get_endpoint_object(uint8_t /*retry_count*/, std::function<void()> /*cb*/) {
}

void mctp::create_transport_and_endpoint(std::string /*module_name*/, std::function<void()> /*cb*/) {
}

bool mctp::request(mc::dict ctx, std::vector<uint8_t>& data, int32_t /*timeout_ms*/,
                   std::string& rsp) {
    auto& handler = get_request_handler();
    if (!handler) {
        rsp.clear();
        return false;
    }
    return handler(ctx, data, rsp);
}

} // namespace dev
